package com.bruce.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bruce.dao.UserRoleDao;
import com.bruce.model.Role;
import com.bruce.model.UserRole;
import com.bruce.service.UserRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class UserRoleServiceImpl implements UserRoleService {
	@Autowired
	private UserRoleDao userRoleDao;
	@Override
	public int insert(UserRole impl) {
		// TODO Auto-generated method stub
		return userRoleDao.insert(impl);
	}

	@Override
	public int update(UserRole impl) {
		// TODO Auto-generated method stub
		return userRoleDao.update(impl);
	}

	@Override
	public PageInfo<UserRole> selectByUid(UserRole impl, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		return new PageInfo<UserRole>(userRoleDao.selectByUid(impl));
	}

	@Override
	public int delete(int uid, int rid) {
		// TODO Auto-generated method stub
		return userRoleDao.delete(uid, rid);
	}
	/**
	 * 判断用户是否拥有角色
	 */
	@Override
	public boolean isUser(int userid) {
		// TODO Auto-generated method stub

		List<Object>  uids = userRoleDao.isUser(userid);
		if(null == uids || uids.size() == 0) {
			return false;
		}
		if( uids.size() == 1) {
			return true;
		}
		return false;
	}

	@Override
	public Role getRoleByRole(int uid) {
		// TODO Auto-generated method stub
		return userRoleDao.getRoleByRole(uid);
	}

}
